package cn.kgc.crowdfundingadminspringboot.service;

import cn.kgc.crowdfundingadminspringboot.mapper.MessageMapper;
import cn.kgc.crowdfundingadminspringboot.pojo.Message;
import cn.kgc.crowdfundingadminspringboot.pojo.MessageExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("messageService")
public class MessageServiceImpl implements MessageService {

    @Resource
    MessageMapper messageMapper;

    @Override
    public PageInfo<Message> select(Integer pageNum, Integer pageSize,  String keyword) {
        // 1.开启分页功能
        PageHelper.startPage(pageNum, pageSize,keyword);

        // 2.执行查询
        MessageExample messageExample=new MessageExample();
        List<Message> list = messageMapper.selectByExample(messageExample);
        // 3.封装为PageInfo对象
        return new PageInfo<>(list);
    }

    @Override
    public void updateAdvertisement(Message message) {
        messageMapper.updateByPrimaryKey(message);
    }
}
